#ifdef DH
#include "DHFileDecoder.h"

#include "../inc/Utils.h"


DHFileDecoder::DHFileDecoder(void)
{
}


DHFileDecoder::~DHFileDecoder(void)
{
		if(fdRead != NULL)
		fclose(fdRead);
}


void DHFileDecoder::startRecvThread()
{
	fdRead = fopen(filename, "rb");
	while(recvThreadRunning == true)
	{
		if(playFlag == PLAY)
		{
		}
		else if(playFlag == PAUSE)
		{
			Sleep(NORMAL_WAIT_TIME);
			continue;
		}
		else if(playFlag == STOP)
		{
			break;
		}
		else
		{
			_print_log("illegal playflag\n");
			break;
		}

		
		int readLength = fread(recvBuf, 1, 1500, fdRead);

		progress += readLength;
		ESPacketBuffer *buffer;
		lfds611_queue_use(qs_pool);
		while(LFDS_SUCCESS != lfds611_queue_dequeue( qs_pool, (void **) &buffer))
		{
			if(recvThreadRunning != true)
				return;
			printf("dequeue failed\n");
			_print_log("dequeue failed\n");
			//lostPacket ++;
			Sleep(NORMAL_WAIT_TIME);
		}
		memcpy(buffer->packetBuffer, recvBuf, readLength);
		buffer->bufferSize = readLength;
		lfds611_queue_use(qs_packet);
		while(LFDS_SUCCESS != lfds611_queue_enqueue( qs_packet, (void *) buffer))
		{
			if(recvThreadRunning != true)
				return;
			lostPacket ++;
			Sleep(NORMAL_WAIT_TIME);
		}
	}
	fclose(fdRead);
}
#else
#endif
